<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html>
<%
	String path = request.getContextPath();
%>
<html>
<head>

<link rel="stylesheet" type="text/css"
	href="<%=path%>/script/easyUI-1.4/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css"
	href="<%=path%>/script/easyUI-1.4/themes/icon.css">
<script type="text/javascript"
	src="<%=path%>/script/easyUI-1.4/jquery-3.2.1.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/script/easyUI-1.4/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/script/easyUI-1.4/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" charset="utf-8"
	src="<%=path%>/script/utf8-jsp/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8"
	src="<%=path%>/script/utf8-jsp/ueditor.all.min.js">
	
</script>
<script type="text/javascript" charset="utf-8"
	src="<%=path%>/script/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
	if (top.location != self.location)
		top.location = self.location;

	$(function() {

		var setting = {
			toolbars : [ [ 'fullscreen', 'source', '|', 'undo', 'redo', '|',
					'bold', 'italic', 'underline', 'fontborder',
					'strikethrough', 'superscript', 'subscript',
					'removeformat', 'formatmatch', 'autotypeset', 'blockquote',
					'pasteplain', '|', 'forecolor', 'backcolor',
					'insertorderedlist', 'insertunorderedlist', 'selectall',
					'cleardoc', '|', 'rowspacingtop', 'rowspacingbottom',
					'lineheight', '|', 'customstyle', 'paragraph',
					'fontfamily', 'fontsize', '|', 'directionalityltr',
					'directionalityrtl', 'indent', '|', 'justifyleft',
					'justifycenter', 'justifyright', 'justifyjustify', '|',
					'touppercase', 'tolowercase', '|', 'link', 'unlink',
					'anchor', '|', 'imagenone', 'imageleft', 'imageright',
					'imagecenter', '|', 'simpleupload', 'insertimage',
					'emotion', 'scrawl', 'insertvideo', 'music', 'attachment',
					'map', 'gmap', 'insertframe', 'insertcode', 'webapp',
					'pagebreak', 'template', 'background', '|', 'horizontal',
					'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
					'inserttable', 'deletetable', 'insertparagraphbeforetable',
					'insertrow', 'deleterow', 'insertcol', 'deletecol',
					'mergecells', 'mergeright', 'mergedown', 'splittocells',
					'splittorows', 'splittocols', 'charts', '|', 'print',
					'preview', 'searchreplace', 'drafts', 'help' ] ],
			//当内容过多时滚动条出现在编辑器里
			autoHeightEnabled : false

		};

		var ue = UE.getEditor('editor', setting);
		
		
		$('#key').combobox({
			onSelect: function(record){
				var value=record.keyValue;
				$('#commitkey').textbox('setValue',value);
			}
		});

		
		$('#fileTree').tree({    
		    url:'<%=path%>/guancangAction/getFileTreeData'   ,
		    onSelect: function(node){
		    	if(node.text=="点击新增文件夹"){
		    		//说明用户选择的是编辑文件夹
		    		$('#fileTree').tree("beginEdit",node.target);
		    		if(node.text==""){
		    			$('#fileTree').tree('update', {
		    				target: node.target,
		    				text: '点击新增文件夹'
		    			});
		    		}
		    	}
		    	$('#wenjianjia').val(node.text);
			},
			onAfterEdit:function(node){
				$('#wenjianjia').val(node.text);
			}
		});  
		

		  $("#fabiaoBtn").bind('click',function(){
			  
			  var isValid = $("#form").form('validate');
			  
			  if(!isValid){
				  //表单验证失败
			  }else{
				  //说明表单验证成功，ajax提交表单
				 
				    $.ajax({
			            //几个参数需要注意一下
			                type: "POST",//方法类型
			                dataType: "json",//预期服务器返回的数据类型
			                url: "<%=path%>/guancangAction/saveupt?id=${article.id}",
			                data: $('#form').serialize(),
			                success: function (result) {
			                    	
			                    if(result.msg != null && result.msg != ""){
			                    	//保存成功
			                    	$.messager.confirm('提示',result.msg,function(r){    
			                    	  location.href="<%=path%>/views/user/main.jsp"; 
			                    	});
			                    }
			                    
			                },
			                error : function() {
			                    alert("系统异常！");
			                }
			            });
				  
				  
			  }
			  
			  
    });
		
		
	})
</script>

</head>
<body class="easyui-layout" >
<form method="post" id="form">
	<div data-options="region:'center'" style="margin-left: 150px;">
	<div style="width: 80%;">
		<div style="margin: 20px">
			<input class="easyui-textbox" name="title"
				data-options="height:40,iconCls:'icon-title',prompt:'请输入标题',required:true" value="${article.title}"
				style="width: 80%; margin-top: 10px;">
		</div>
		<div id="editorDiv">
				<script id="editor" type="text/plain" style="width: 800px;height: 500px;" name="content" >${article.content}</script>
		</div>
	</div>
	</div>
	<div data-options="region:'east'" style="width: 400px">
		
		<div style="margin: 50px;">
			<select id="cc" class="easyui-combobox" name="quanxian" style="width:200px;height: 40px">   
			    <option value="公开">公开</option>   
			    <option value="私密">私密</option>   
			</select>  
		</div>
		
		<div style="margin: 50px;">
		 	关键字:<br><br>
		 	<input class="easyui-textbox" data-options="required:true" id="commitkey" style="width:300px;height: 30px;" name="key" value="${article.key}"> <br>
		 	<input id="key" class="easyui-combobox"  data-options="valueField:'keyValue',textField:'keyText',url:'<%=path%>/guancangAction/getKey'" />  
 
		</div>
		
		<div style="margin: 50px;">
			选择存放的文件夹:<br><br>
			<ul id="fileTree" data-options="required:true"></ul> 
			<input type="hidden"  name="wenjianjia" id="wenjianjia">
		</div>
		
		
			<div style="margin: 50px;">
		 	标签:<br><br>
		 	<input id="label" class="easyui-combobox" name="label" data-options="valueField:'keyValue',textField:'keyText',url:'<%=path%>/guancangAction/getLabel'" />  
 
		</div>
	</div>

<div data-options="region:'south'" style="height: 60px;">
	<a id="fabiaoBtn" class="easyui-linkbutton"
					data-options="iconCls:'icon-ok'" style="width: 120px; height: 32px;margin-top: 10px;margin-left: 550px">发表</a>
				<a id="backBtn" class="easyui-linkbutton"
					data-options="iconCls:'icon-back'"
					style="width: 120px; height: 32px;margin-top: 10px;margin-left: 50px; ">取消</a>
</div>
</form>
</body>

</html>